package lang

import (
	"JVM/Jvmgo/GoToJVM/native"
	"JVM/Jvmgo/GoToJVM/runtimeData"
	"JVM/Jvmgo/GoToJVM/runtimeData/heap"
)

/*
intern 方法可以使java类库使用我们自定义的StringPool
*/

func init() {
	native.Register("java/lang/String", "intern", "()Ljava/lang/String;", intern)
}

// public native String intern()
func intern(frame *runtimeData.Frame) {
	this := frame.LocalVars().GetThis()
	interned := heap.InternString(this)
	frame.OperandStack().PushRef(interned)
}
